#include<stdio.h>
int movex[] = {-1, 1, 0, 0, 0, 0};
int movey[] = {0, 0, -1, 1, 0, 0};
int movez[] = {0, 0, 0, 0, -1, 1};
int l, r, c;
int answer = -1;
char position[31][31][31];

struct Node
{
      int x, y, z, step;
};

Node queue[27001] ;
Node start, end;


void bfs()
{
     int i;
     Node now, next;
     int head = 0, tail = 1;
     start.step = 0;
     
     now = start;
     queue[head] = now;
     
     
     while(tail > head)
     {
          
          now = queue[head];
          head ++;
          if(now.x == end.x && now.y == end.y && now.z == end.z)
          {
              answer = now.step;
              break;
          }
          for(i = 0; i < 6; i++)
          {
                next.x = now.x + movex[i];
                next.y = now.y + movey[i];
                next.z = now.z + movez[i];
                next.step = now.step + 1;
                if(next.x < r && next.x >= 0 
                && next.y < c && next.y >= 0
                && next.z < l && next.z >= 0 
                && position[next.z][next.x][next.y] != '#'
                )
                {
                    queue[tail] = next;
                    tail ++;
                    position[next.z][next.x][next.y] = '#';
                }
                
          }
     }
}


int main()
{
    int i, j, k, m, n; 
    while(1)
    {
             scanf("%d%d%d", &l, &r, &c);
             if(l == 0 && r == 0 && c == 0) break;
             for(i = 0; i < l; i++)
             {
                   for(j = 0; j < r; j++)
                        scanf("%s", position[i][j]);
             }
    
             for(k = 0; k < l; k++)
                   for(m = 0; m < r; m++)
                         for(n = 0; n < c; n++)
                         {
                               if(position[k][m][n] == 'S') 
                               {
                                     start.z = k;
                                     start.x = m;
                                     start.y = n;
                               }   
                               else if(position[k][m][n] == 'E')
                               {
                                     end.z = k;
                                     end.x = m;
                                     end.y = n;
                               }
                         
                         }
             bfs();
             if(answer == -1)
                       printf("Trapped!\n");
             else printf("Escaped in %d minute(s).\n", answer);
             answer = -1;
    }
    
    return 0;
}



